<?php
namespace App\Repositories\Backend;

use App\Models\Subject;
use Illuminate\Support\Facades\Auth;

class SubjectRepository extends CommonRepository
{

    public function __construct(Subject $subject)
    {
        parent::__construct($subject);
    }

    /**
     * 列表
     * @param  array $input 查询条件
     * @return object
     */
    public function getLists($input)
    {
        $default_search = [
            'filter' => ['id' , 'subject_name', 'comment', 'subject_image1','subject_image2' , 'order','status','created_at'],
            'sort'   => [
                'order' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->parseWheres($search)->paginate();
    }


    /**
     * 新增
     * @param  string   $subject_name    科目名称
     * @param  string   $comment         科目简介
     * @param  int      $order           排序
     * @param  int      $status          状态
     * @param  string   $subject_image1  海报图
     * @param  string   $subject_image2  详细图
     * @return object
     */
    public function create($subject_name, $comment, $order, $status , $subject_image1 , $subject_image2)
    {
        $result = $this->model->create([
            'subject_name'   => $subject_name,
            'comment'        => $comment,
            'order'          => $order,
            'status'         => $status,
            'subject_image1' => $subject_image1,
            'subject_image2' => $subject_image2,
        ]);

        return $result;
    }


    /**
     * 编辑
     * @param  int $id
     * @param  string   $subject_name    科目名称
     * @param  string   $comment         科目简介
     * @param  int      $order           排序
     * @param  int      $status          状态
     * @param  string   $subject_image1  海报图
     * @param  string   $subject_image2  详细图
     * @return object
     */
    public function update($id, $subject_name, $comment, $order, $status , $subject_image1 , $subject_image2)
    {
        $result = $this->model->where('id', $id)->update([
            'subject_name'   => $subject_name,
            'comment'        => $comment,
            'order'          => $order,
            'status'         => $status,
            'subject_image1' => $subject_image1,
            'subject_image2' => $subject_image2,
        ]);

        return $result;
    }

    public function subjectdata($input)
    {
        $default_search = [
            'filter' => ['id' , 'subject_name', 'comment', 'subject_image1','subject_image2' , 'order','status','created_at'],
            'sort'   => [
                'order' => 'asc',
            ],
        ];
        $search = $this->parseParams($default_search, $input);
        return $this->model->where($input)->with('doctor')->paginate();
    }



}